from common.base_page import BasePage
from appium.webdriver.common.appiumby import AppiumBy


class Unfollow(BasePage):
    # 点击头像
    headSculpture_loc = (AppiumBy.ID, 'com.jhss.youguu:id/head_pic')
    # 登录按钮
    loginBtn_loc = (AppiumBy.ID, 'com.jhss.youguu:id/btn_login')
    # 账号密码登录
    zhmm_loc = (AppiumBy.ID, 'com.jhss.youguu:id/tv_change_login_type')
    # 输入账号
    zh_loc = (AppiumBy.ID, 'com.jhss.youguu:id/et_username')
    # 输入密码
    mm_loc = (AppiumBy.ID, 'com.jhss.youguu:id/et_password')
    # 点击登录
    clicklogin_loc = (AppiumBy.ID, 'com.jhss.youguu:id/bt_login')
    # 点击关注
    follow_loc = (AppiumBy.XPATH, '//android.widget.TextView[@text="关注"]')
    # 获取关注数
    follownum_loc = (AppiumBy.ID, 'com.jhss.youguu:id/tv_focus_num')
    # 点击取消
    cancellation_loc = (AppiumBy.ID, 'com.jhss.youguu:id/commontAttText')
    # 返回
    back_loc = (AppiumBy.XPATH, '//android.widget.ImageButton[@bounds="[24,48][70,138]"]')

    def login(self, name, pwd):
        self.click_ele(self.headSculpture_loc)
        self.click_ele(self.loginBtn_loc)
        self.click_ele(self.zhmm_loc)
        self.send_keys(self.zh_loc, name)
        self.send_keys(self.mm_loc, pwd)
        self.click_ele(self.clicklogin_loc)

    # 取消关注执行
    def qxgz(self):
        self.click_ele(self.follow_loc)
        self.click_ele(self.cancellation_loc)
        self.click_ele(self.back_loc)
        self.swip_down(1)  # 下滑刷新页面1次
